<!DOCTYPE HTML>
<html>
<head>
<title>Low Latency 2D Canvas get/putImageData Test</title>
<style type="text/css">
.nomargin {
  margin: 0px auto;
}
</style>
<script>
let g_swapsBeforeAck = 15;

function waitForFinish()
{
  if (g_swapsBeforeAck == 0) {
    domAutomationController.send("SUCCESS");
  } else {
    g_swapsBeforeAck--;
    window.requestAnimationFrame(waitForFinish);
  }
}

function main()
{
  let c1 = document.getElementById("c1");
  let ctx1 = c1.getContext("2d", {"desynchronized": true});

  let c2 = document.getElementById("c2");
  let ctx2 = c2.getContext("2d", {"desynchronized": true});

  ctx1.fillStyle = "#FF0000";
  ctx1.fillRect(0, 0, 100, 100);

  let imageData = ctx1.getImageData(0, 0, 100, 100);
  ctx2.putImageData(imageData, 0, 0);

  ctx1.fillStyle = "#00FF00";
  ctx1.fillRect(0, 50, 50, 50);

  imageData = ctx1.getImageData(0, 50, 50, 50);
  ctx2.putImageData(imageData, 0, 50);

  ctx1.fillStyle = "#0000FF";
  ctx1.fillRect(50, 0, 50, 50);

  imageData = ctx1.getImageData(50, 0, 50, 50);
  ctx2.putImageData(imageData, 50, 0);

  waitForFinish();
}
</script>
</head>
<body onload="main()">
<div id="container" style="position:absolute; top:0px; left:0px">
<canvas id="c1" width="100" height="100" class="nomargin"></canvas>
<canvas id="c2" width="100" height="100" class="nomargin"></canvas>
</div>
</body>
</html>
